﻿-- =============================================
-- Author:		<Author,徐福龙>
-- Create date: <Create Date,2012 03 01>
-- Description:	<Description,报销申请列表 用于显示摘要明细>
-- =============================================
CREATE PROCEDURE [dbo].[proc_L_Reimbursement_GetList_More]
(
@Pid int
)
AS
BEGIN

	SET NOCOUNT ON;

;WITH list as 
(
SELECT 
	ROW_NUMBER() OVER (ORDER BY Id ) AS Row
	,[id]
	,[Pid]
	,[Reason]
	,[Prices]
--	,[userid]
--	,ISNULL([lrrq],'1900-01-01') as [lrrq]
--	,[CateOneId]
	,ISNULL([CateOneName],'--') as [CateOneName]
--	,[CateTwoId]
	,ISNULL([CateTwoName],'--') as [CateTwoName]
--	,[SubjectId]
	,ISNULL([SubjectName],'--') as [SubjectName]
--票据编号
	,Pjbh

	FROM [L_Reimbursement_Item]
	where pid=@Pid
)

Select 
L.* 

--摘要
,ISNULL(LR.Summary ,'---') as Summary
--备注
,ISNULL(LR.Memo ,'---') as Memo
--公司
,ISNULL(LR.CompanyName ,'---') as CompanyName
--部门
,ISNULL(LR.DepartmentName ,'---') as DepartmentName
--申请人
,ISNULL(LR.EName ,'---') as EName
--申请金额
,ISNULL(LR.[Money] ,0) as [Money]
--申请日期
,ISNULL(LR.[lrrq],'1900-01-01') as [lrrq]


--一级审批
,ISNULL(LR.PZflag ,0)as PZflag
,ISNULL(LR.PZPersonName ,'---') as PZPersonName
,ISNULL(LR.PZYJ ,'---') as PZYJ
,ISNULL(LR.PZRQ ,'1900-01-01') as PZRQ

--二级审批
,ISNULL(LR.PZflag1 ,0)as PZflag1
,ISNULL(LR.PZPersonName1 ,'---') as PZPersonName1
,ISNULL(LR.PZYJ1 ,'---') as PZYJ1
,ISNULL(LR.PZRQ1 ,'1900-01-01') as PZRQ1

--财务级审批
,ISNULL(LR.SHflag ,0)as SHflag
,ISNULL(LR.SHPersonName ,'---') as SHPersonName
,ISNULL(LR.SHYJ ,'---') as SHYJ
,ISNULL(LR.SHRQ ,'1900-01-01') as SHRQ

--	报销信息
      ,ISNULL(LR.[BXflag],0)as [BXflag]
      ,LR.[BXJE]
      ,LR.[BXLoanId]
--	付款信息
      ,ISNULL(LR.[FKflag],0)as [FKflag]
      ,LR.[FKJE]
      ,LR.[FKLoanId]
--	还款信息
      ,ISNULL(LR.[HKflag],0)as [HKflag]
      ,LR.[HKJE],LR.PaymentTypeName,LR.BankName

From list L,L_Reimbursement LR
WHERE L.PID=LR.ID
order by L.row

END
